package extend;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

public class MyJdbcNiube {

    StatementSetter statementSetter;
    PreparedStatement preparedStatement;

    private MyJdbcNiube(StatementSetter statementSetter,PreparedStatement preparedStatement){
        this.statementSetter =statementSetter;
        this.preparedStatement = preparedStatement;
    }


    public static MyJdbcNiube niube(String sql,StatementSetter statementSetter, Properties connectionProperties) throws SQLException {
        String url = connectionProperties.getProperty("jdbc.url");
        String username = connectionProperties.getProperty("jdbc.username");
        String password = connectionProperties.getProperty("jdbc.password");
        Connection connection = DriverManager.getConnection(url, username, password);
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        return new MyJdbcNiube(statementSetter,preparedStatement);
    }



    public void emitData(String json) throws SQLException {
        statementSetter.suiBian(preparedStatement,json);
        preparedStatement.execute();

    }

}
